package com.frxuexi.park2302.news

import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class NewsViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<NewsIntent>() {
    override fun handlerIntent(it: NewsIntent) {
        when(it){
            is NewsIntent.getNews->httpRequest(apiService.getNews())
            is NewsIntent.getNewsByKey->httpRequest(apiService.getNewsByKey(it.key))
            is NewsIntent.addNews->httpRequest(apiService.addNews(toBody(it.item)))
            is NewsIntent.revokeNews->httpRequest(apiService.revokeNews(it.id),RequestType.UPDATE)
        }
    }
}